package interfaz;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import java.util.*;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.WindowConstants;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.plaf.basic.BasicTabbedPaneUI.TabbedPaneLayout;

import java.awt.LayoutManager;

import dominio.Inmueble;
//import info.clearthought.layout.TableLayout;
import excepciones.InmuebleYaExiste;
import java.awt.BorderLayout;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
@SuppressWarnings("serial")
public class VentanaDetalle extends javax.swing.JFrame {
	private String tipoVentana;
	private JLabel id, piso, puerta;
	private JLabel escalera;
	private JPanel jPanel2;
	private JButton guardar;
	private JPanel jPanel1;
	private JTextField idTexto;
	private JTextField escaleraTexto;
	private JTextField pisoTexto;
	private JTextField puertaTexto;
	private JButton volver;
	private ModeloTablaInmueble modelo;
	private Inmueble i;
	private Inmueble inm;
	
	public VentanaDetalle(ModeloTablaInmueble modelo) {
		super();
		this.modelo=modelo;
		//Esto es el boton de Anyadir
		initGUI();
		guardar.setEnabled(true);
	}
	
	public VentanaDetalle(Inmueble i) {
		super();
		this.i=i;
		initGUI();
		//Esto es el boton de Detalle
		idTexto.setText(Integer.toString(i.getId()));
		escaleraTexto.setText(i.getEscalera());
		pisoTexto.setText(i.getPiso());
		puertaTexto.setText(i.getPuerta());
		guardar.setEnabled(false);
	}
	
	class SalirHandler implements ActionListener {
		public void actionPerformed(ActionEvent e){
			VentanaDetalle.this.dispose();
		}
	}
	
	class GuardarHandler implements ActionListener {
		public void actionPerformed(ActionEvent e){
			try {
				inm = new Inmueble();
				try{
					inm.setId(Integer.parseInt(idTexto.getText()));
				}catch(NumberFormatException ee){
					System.out.println("Usted debe ingresar un valor entero como 'id'");
				}
				inm.setEscalera(escaleraTexto.getText());
				inm.setPiso(pisoTexto.getText());
				inm.setPuerta(puertaTexto.getText());
				modelo.addInmueble(inm);
			} catch (InmuebleYaExiste e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			VentanaDetalle.this.dispose();
		}
	}
	
	private void initGUI() {
		try {
			this.setTitle("Detalle Inmueble");
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			pack();
			setSize(400, 300);
			BorderLayout thisLayout = new BorderLayout();
			getContentPane().setLayout(thisLayout);
			this.setLocation(new java.awt.Point(415, 165));

			{
				jPanel1 = new JPanel();
				GridBagLayout jPanel1Layout = new GridBagLayout();
				getContentPane().add(jPanel1, BorderLayout.CENTER);
				jPanel1Layout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1};
				jPanel1Layout.rowHeights = new int[] {7, 7, 7, 7};
				jPanel1Layout.columnWeights = new double[] {0.0, 0.1, 0.1, 0.1};
				jPanel1Layout.columnWidths = new int[] {89, 7, 7, 7};
				jPanel1.setLayout(jPanel1Layout);
				jPanel1.setPreferredSize(new java.awt.Dimension(384, 224));
				{
					idTexto = new JTextField();
					jPanel1.add(idTexto, new GridBagConstraints(1, 0, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
					idTexto.setPreferredSize(new java.awt.Dimension(28, 22));
				}
				{
					id = new JLabel();
					jPanel1.add(id, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					id.setText("id: ");
					id.setPreferredSize(new java.awt.Dimension(308, 218));
				}
				{
					puerta = new JLabel();
					jPanel1.add(puerta, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					puerta.setText("Puerta: ");
				}
				{
					escalera = new JLabel();
					jPanel1.add(escalera, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					escalera.setText("Escalera: ");
				}
				{
					piso = new JLabel();
					jPanel1.add(piso, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
					piso.setText("Piso: ");
				}
				{
					escaleraTexto = new JTextField();
					jPanel1.add(escaleraTexto, new GridBagConstraints(1, 1, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
					escaleraTexto.setPreferredSize(new java.awt.Dimension(28, 22));
				}
				{
					pisoTexto = new JTextField();
					jPanel1.add(pisoTexto, new GridBagConstraints(1, 2, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
					pisoTexto.setPreferredSize(new java.awt.Dimension(28, 22));
				}
				{
					puertaTexto = new JTextField();
					jPanel1.add(puertaTexto, new GridBagConstraints(1, 3, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
					puertaTexto.setPreferredSize(new java.awt.Dimension(28, 22));
				}
			}
			{
				jPanel2 = new JPanel();
				getContentPane().add(jPanel2, BorderLayout.SOUTH);
				jPanel2.setPreferredSize(new java.awt.Dimension(384, 37));
				{
					guardar = new JButton();
					jPanel2.add(guardar);
					guardar.setText("Guardar");
					GuardarHandler guh = new GuardarHandler();
					this.guardar.addActionListener(guh);
				}
				{
					volver = new JButton();
					jPanel2.add(volver);
					volver.setText("Volver");
					SalirHandler slh = new SalirHandler();
					this.volver.addActionListener(slh);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
